package org.lg.web.controller;

import org.lg.config.*;
import org.lg.dto.BaseDto;
import org.lg.dto.MessageEnum;
import org.lg.entity.Student;
import org.lg.page.PageInfo;
import org.lg.service.StudentService;
import org.lg.service.impl.StudentServiceImpl;
import org.lg.vo.Vo;

/**
 * 学生类的控制器 门卫 对url的响应处理
 */
@Controller("/studentController")
public class StudentController {
    @Resource
    StudentService studentService;
    /**
     * 查询全部学生 示例 无参数方法
     * @return
     */
    @RequestMapping("/getStudents")
    @ResponseBody
    public BaseDto getAllStudents() throws Exception {
        return  studentService.getAllStudents();
    }

    @RequestMapping("/getStudentByPage")
    @ResponseBody
    public BaseDto getStudentByPage(@RequestBody PageInfo pageInfo) throws Exception {
        return  studentService.getStudentByPage(pageInfo);
    }

    @RequestMapping("/getTop20Student")
    @ResponseBody
    public BaseDto getTop20Student() throws Exception {
        return  studentService.getTop20Student();
    }

    @RequestMapping("/getScoreBySno/{id}")
    @ResponseBody
    public BaseDto getScoreBySno(String sno) throws Exception {
        return  studentService.getScoreBySno(sno);
    }




    /**
     * 根据主键查询 示范简单参数
     * @param sno
     * @return
     */
    @RequestMapping("/getStudentById/{id}")
    @ResponseBody
    public BaseDto getStudentById(String sno) throws Exception{
        return studentService.getStudentById(sno);
    }

    /**
     * 根据主键查询的学生关联班级和班主任信息
     * @param sno
     * @return
     * @throws Exception
     */
    @RequestMapping("/selectBySnoWithClazzAndTeacher/{id}")
    @ResponseBody
    public BaseDto selectByPrimaryKeyWithClazzAndTeacher(String sno)  throws Exception {
        return studentService.selectByPrimaryKeyWithClazzAndTeacher(sno);
    }
    /*

     */
    @RequestMapping("/addStudent")
    @ResponseBody
    public BaseDto addStudent(@RequestBody Student student) throws Exception{
        studentService.addStudent(student);
        BaseDto dto = new BaseDto(MessageEnum.ADDSTUDENTSUCCESS,student);
        return  dto;
    }

    @RequestMapping("/editStudent")
    @ResponseBody
    public BaseDto editStudent(@RequestBody Student student) throws Exception {
        return  studentService.editStudent(student);
    }
    @RequestMapping("/cancelCourse")
    public BaseDto cancelCourse(String courseJson){
        BaseDto dto = new BaseDto(MessageEnum.GETSTUDENTBYIDSUCCESS);
        return  dto;
    }

    @RequestMapping("/getScBySnoAndByPage")
    @ResponseBody
    public BaseDto getScBySnoAndByPage(@RequestBody PageInfo pageInfo) throws Exception {
        return  studentService.getScBySnoAndByPage(pageInfo);
    }


    @RequestMapping("/getClassMateByCno")
    @ResponseBody
    public BaseDto getClassMateByCno(@RequestBody Vo vo) throws Exception {
        return  studentService.getClassMateByCno(vo);
    }

    @RequestMapping("/getClassMateByCnoAndByPage")
    @ResponseBody
    public BaseDto getClassMateByCnoAndByPage(@RequestBody PageInfo pageInfo) throws Exception {
        return  studentService.getClassMateByCnoAndByPage(pageInfo);
    }



}

